<div class="div_form_content">
<?$gn = Group::group_names();?>
<?$cn = Group::company();?>
<div style="margin:10px">
<h1>Users management</h1>
    <table>
        <tr>
            <td>
                 Users list | <a href="index.php?m=administration&a=create_user">Create new user</a>
            </td>
            <td>
                <div style="float:right; margin-right: 50px;">
                    <input type="text" id="search" value="<?=$s?>"/>
                    <input type ="button" value="search" onclick="search()"/>
                </div>
            </td>
        </tr>

    </table>


<table >
   <tr>
       
       <th>User_name</th>
       <th>User_email</th>
       <th>User_realname</th>
       <th>User_group</th>
       <th>From</th>
       <th>Action</th>
   </tr>
   <?foreach($users as $u):?>
   <?$group_name = (key_exists($u['group_id'],$gn))? $gn[$u['group_id']] : '<i>Unassigned</i>'; ?>
   
   <?foreach($cn as $c):?>
   <?$company=($c['idcustomers']==$u['idcustomer'])? $c['namecustomer'] : '<i>Unassigned</i>';?>
   <?endforeach?> 
   
   <tr <?if($u['status']==0): ?> style="color:#999" <?endif?>>
       <td><?=$u['user_name']?></td>
       <td><?=$u['user_email']?></td>
       <td><?=$u['user_realname']?></td>
       <td><?=$group_name?></td>
       <td><?$company?></td>
       <td><a href="index.php?m=administration&a=edit_user&user_id=<?=$u['user_id']?>">Edit</a> |<a href="javascript:deleteUser(<?=$u['user_id']?>)" >Delete</a></td>
   </tr>
   <?endforeach?>
</table>


<div id="page-number">
    <div id="page-number-left">
        Page 
        <?if($num_pages<=5):?> <!--11111so trang < 5 in tu 1 den 5-->
            <?for($i=1;$i<=$num_pages;$i++):?>
            <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
            <?endfor?>
        <?else:?>

            <?if($page_num<5):?> <!--222222222-so trang > 5  neu trang hienj tai <5 in tu 1 den 5-->
				
                <?for($i=1;$i<=5;$i++):?>
                <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                <?endfor?>
                <span style="border: 1px solid #eee; padding: 5px;">...</span>
                <span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="<?=$num_pages?>"><?=$num_pages?></span>

            <?else:?> <!--so trang > 5  neu trang hienj tai >= 5 phải kiểm tra lại num_pages-->
                <?if($num_pages>$page_num+4):?>
					<span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="1">1</span>
					<span style="border: 1px solid #eee; padding: 5px;">...</span>
                    <?for($i=$page_num-3;$i<=$page_num+3;$i++):?>
                    <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                    <?endfor?>
                    <span style="border: 1px solid #eee; padding: 5px;">...</span>
                    <span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="<?=$num_pages?>"><?=$num_pages?></a></span>
                 <?else:?>
					<span style="border: 1px solid #ddd; padding: 5px;" class="span_page_number" title="1">1</span>
					<span style="border: 1px solid #ddd; padding: 5px;">...</span>
                    <?for($i=$page_num-3;$i<=$num_pages;$i++):?>
                    <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                    <?endfor?>
                  <?endif?>
            <?endif?> <!--222222222-so trang > 5  neu trang hienj tai <5 in tu 1 den 5-->
        <?endif?><!--11111so trang < 5 in tu 1 den 5-->

    </div>
</div>
</div>
</div>
<script type="text/javascript">

function deleteUser(userid){

    var conf = confirm("Are you sure you want to delete this user?");
    if(conf == true){
         var url="index.php?m=administration&a=delete_user&user_id="+userid;
         window.location=url;
         //alert (url);
    }

}

function search(){
    var word=$('#search').val();
    var url="index.php?m=administration&a=index&se="+word;
    window.location=url;
}

</script>

<style>
    table{
        width: 100%;
        margin: 20px;
        
    }
td
{
padding:3px;
}
</style>